<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
	<meta charset="utf-8">
	<title>后台用户管理</title>
	<meta name="renderer" content="webkit">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
	<link rel="stylesheet" href="../../layui/css/layui.css" media="all">
	<style>
		.blogUser-con .layui-table-view {
			border: none;
		}
		
		.blogUser-con .layui-table-box {
			margin-top: 10px;
		}
		
		.blogUser-con {
			padding: 0 15px 15px 15px;
			margin-bottom:50px;
		}
		.blogUser-con  .layui-table-tool-self{
			display:none;
		}
		.blogUser-con .not_border_left {
			border-left: none !important;
		}
		
		.blogUser-con .blogUser dl dd.layui-this {
			background-color: #1E9FFF !important;
		}
		
		.blogUser-con .hide {
			display: none;
		}
		
		.blogUser-con .show {
			display: block;
		}
		
		.blogUser-con .btn_size {
			height: 28px !important;
			line-height: 28px !important;
		}
		
		.blogUser-con .layui-table-body table tbody .layui-table-hover {
			background: #fffdd3 !important;
		}
		
		.blogUser-con .layui-table-body table tbody .layui-table-click {
			background: #fdef9b !important;
		}
		
		.blogUser-con .layui-table, .layui-table-view {
			border: none;
			margin-top: 0;
		}
		
		#add-AdminUser {
			display: none;
			z-index: 999 !important;
		}
		
		#add-AdminUser .artTypeLayer {
			width: 90%;
			margin-left: auto;
			margin-right: auto;
			padding-top: 20px;
		}
		.adminuserdetail{
			padding:20px;
			display: none;
		}
		.adminuserdetail table tr td{
			padding: 15px;text-align: center;
		}
		.adminuserdetail .tdbck{
			background: #f2f2f2;
			width: 30%;
		}
	</style>
</head>
<body>

	<div class="blogUser-con">
		<blockquote class="layui-elem-quote not_border_left">
			<form class="layui-form" action="">
			  	 <div class="layui-inline">
		             <label class="layui-form-label">选择赛程</label>
		            <div class="layui-input-inline">
		              <select name="arrange" id="arrange" lay-filter="arrange">
		                <option value="00">请选择赛程</option>
		              </select>
		            </div>
	            </div>
			    <div class="layui-inline">
		            <label class="layui-form-label">选择分组</label>
		            <div class="layui-input-inline">
		              <select name="group" id="group" lay-filter="group">
		                <option value="00">请选择分组</option>
		              </select>
		            </div>
		        </div>
			    <div class="layui-inline">
	     	   		<button id="btnselfrontinfo" type="button" class="layui-btn layui-bg-blue">查询</button>
			    </div>
			</form>
		</blockquote>

		<script type="text/html" id="barDemo">
			<a class="layui-btn layui-btn-xs" id="edit" lay-event="edit">录入成绩</a>
			<a class="layui-btn layui-btn-danger  layui-btn-xs" lay-event="del">修改成绩</a>
		</script>

		<!-- 表格开始 -->
		<table class="layui-hide" name="achiinfo" id="achiinfo" lay-filter="achiinfo"></table>
		<!-- 表格结束 -->
		
	</div>
	<script src="../../js/jquery-3.3.1.js" charset="utf-8"></script>
	<script src="../../layui/layui.js" charset="utf-8"></script>
	<script src="../../js/loadselect.js" charset="utf-8"></script>
	<script>
	layui.use([ 'table', 'form', 'layer', 'laydate', 'laytpl', 'element' ], function() {
		var table = layui.table, form = layui.form, 
			layer = layui.layer, $ = layui.jquery,
			laydate = layui.laydate, laytpl = layui.laytpl,
			element = layui.element;
			
		
		/* 点击查询对学院信息进行筛选(模糊查询) */
		$("#btnselfrontinfo").click(function(){
			querylist();//调用局部刷新
			
		});
		
		function querylist(){
			var arrange=$("#arrange").val();
			var group=$("#group").val();
			if(arrange == 00){
				layer.msg("请选择赛程");
				return;
			}
			if(group == 00){
				layer.msg("请选择分组");
				return;
			}
			var param = '?arrangeid=' + arrange + '&groupid=' + group;
	
			/*加载表格*/
			table.render({
				elem : '#achiinfo',
				id:'achiinfo',
				url : '../../scoremana/getallathletesinfo' + param,
				title : '后台通知管理数据表',
				height: "full-160",
				skin : 'line',
				even : true,
				cols : [ 
				     [ {field:'athletesid', title:'运动员编号', width:150,align : 'center'}
				      ,{field:'athletesname', title:'运动员', width:150,align : 'center'}
				      ,{field:'groupid', title:'分组编号', width:100,hide:true}
				       ,{field:'arrangename', title:'赛程', width:150,align : 'center'}
				      ,{field:'groupname', title:'组名', width:150,align : 'center'}
				      ,{field:'arrangeid', title:'赛程编号', width:100,hide:true}
				      ,{field:'signupid', title:'报名编号', width:100,hide:true}
				      ,{field:'projectid', title:'项目编号', width:100,hide:true}
				      ,{field:'preliminaries', title:'预赛成绩', width:200,align : 'center'}
				      ,{field:'preliminariesrank', title:'小组排名', width:100,align : 'center'}
				      ,{field:'projectname', title:'所报项目', width:150,align : 'center'}
				      ,{title : '操作',toolbar : '#barDemo',align : 'center', width:250} 
				     ] 
				 ],
				 page: {
						layout: ['prev', 'page', 'next', 'skip', 'count', 'limit'],
						groups: 5,
						limit: 10,
						limits: [10, 20, 30, 40, 50],
						theme: '#1E9FFF',						
				 },
			});
		}
		
		
			//监听行工具事件
			  table.on('tool(achiinfo)', function(obj){ //注：tool 是工具条事件名，test 是 table 原始容器的属性 lay-filter="对应的值"
			    var data = obj.data //获得当前行数据
			    ,layEvent = obj.event; //获得 lay-event 对应的值
			    if(layEvent === 'detail'){
			      layer.msg('查看操作');
			    } else if(layEvent === 'del'){//修改成绩
			    
			     	var groupid = obj.data.groupid;
			
		             sessionStorage.setItem('Groupid',groupid);
			    
			    	//alert(obj.data.signupid)
			    	//判断当前是否有报名编号
				    if(obj.data.signupid == null || obj.data.signupid == "" || obj.data.signupid == undefined){
			  			 layer.msg("请重新选择修改数据");
			  			 return;
			  		}
			  		if(obj.data.preliminaries == null || obj.data.preliminaries == "" || obj.data.preliminaries == undefined){
			    		 layer.msg("当前状态不允许修改成绩");
			  			 return;
			    	}else{
			  			//查询当前是否可以修改成绩
			  			$.ajax({
							url:"../../scoremana/getisbysignupid?signupid=" + obj.data.signupid,
							type:"POST",
							data:null,
							dataType : "json",
							xhrFields :{
								withCredentials: true
							},
							contentType:'application/json;charset=UTF-8',
							success:function(e){
								//alert(e.msg)
								if(e.code == 0){//成功说明可以修改
									 //alert(e.data.signupid)
									 //console.log(e);
									  //alert(e.data.preliminaries.length)
									 
						             sessionStorage.setItem('Signupid',obj.data.signupid);//把这个值传到父页面去，做修改专用
							         var name = encodeURIComponent(data.toolName);
							           //alert(name);
							           layer.open({
							              type: 2,
							              title: '修改成绩',
							              shadeClose: true,
							              shade: 0.5,
							              closeBtn:'1',//右上角xx关闭
							              area: ['500px','350px'],
							              content:'modachieve.jsp',
							              btn: ['确定', '取消'],
							              yes: function(index, layero){
							              
								            //点击确认触发 iframe 内容中的按钮提交
								            var submit = layero.find('iframe').contents().find("#layuiadmin-app-form-submit");
								            submit.click();
								       	 },
							              success : function(layero, index){
								            var body = layui.layer.getChildFrame('body', index);
								            if(layEvent === 'del'){//给控件赋值
								                body.find("#scoreid").val(e.data.scoreid);
								                body.find("#signupid").val(e.data.signupid);
								                if(e.data.preliminaries.length == 12){
								               		body.find("#result2").val(e.data.preliminaries);
								                }else{
								                	body.find("#result1").val(e.data.preliminaries);
								                }
								                form.render();
								            }
								            setTimeout(function(){
								                layui.layer.tips('点击此处返回项目列表', '.layui-layer-setwin .layui-layer-close', {
								                    tips: 3
								                });
								            },100)
								        }
							         });
								}else{
									layer.msg("当前数据不允许修改成绩",{icon:5});
								}
							},
							error:function(e){
								layer.msg("当前数据不允许修改成绩",{icon:5});
								
							}
						})
			  		}
				    
			    } else if(layEvent === 'edit'){//录入成绩
			    
			    	if(obj.data.preliminaries != undefined){
			    		 layer.msg("当前状态不允许录入成绩");
			  			 return;
			    	}
			    	
			    
			         var name = encodeURIComponent(data.toolName);
			           //alert(name);
			           layer.open({
			              type: 2,
			              title: '录入成绩',
			              shadeClose: true,
			              shade: 0.5,
			              closeBtn:'1',//右上角xx关闭
			              area: ['500px','350px'],
			              content:'addachieve.jsp',
			              btn: ['确定', '取消'],
			              yes: function(index, layero){
			              
				            //点击确认触发 iframe 内容中的按钮提交
				            var submit = layero.find('iframe').contents().find("#layuiadmin-app-form-submit");
				            submit.click();
				            //表格刷新
				          	table.reload('studentinfo');
				        },
			              success : function(layero, index){
				            var body = layui.layer.getChildFrame('body', index);
				            if(layEvent === 'edit'){
				                // 取到弹出层里的元素，并把编辑的内容放进去
				                body.find("#signupid").val(obj.data.signupid);  //将选中的数据的id传到编辑页面的隐藏域，便于根据ID修改数据			                
				                body.find("#groupid").val(obj.data.groupid);
				                // 记得重新渲染表单
				                form.render();
				            }
				            setTimeout(function(){
				                layui.layer.tips('点击此处返回项目列表', '.layui-layer-setwin .layui-layer-close', {
				                    tips: 3
				                });
				            },100)
				        }
			         });
			     }
			  });
		
		
		//获取下拉框的值
		$.ajax({
			type: 'get',
			url: '../../dropdown/getarrange',
			datatype: 'json',
			success: function(roledata) {
				if(roledata.code == 0) {
					var str = "";
					for(var i = 0; i < roledata.count; i++) {
						str += '<option value=' + roledata.data[i].arrangeid + '>' + roledata.data[i].arrangename + '</option>';
					}
			   		 $("#arrange").append(str);
					form.render();
				} else {
						layer.msg("赛程信息获取失败");
				}
			},
			error: function() {
				layer.msg("赛程信息获取失败");
			}
		});
		
		//赛程分组的下拉联动
		form.on('select(arrange)', function(data){
			//同时刷新两个数据，实现三级联动
	   		 $.ajax({
				type: 'get',
				url: '../../dropdown/getgroupbyid?Arrangeid='+data.value,
				datatype: 'json',
				success: function(roledata) {
					if(roledata.code == 0) {
						var str = "";
						for(var i = 0; i < roledata.count; i++) {
							str += '<option value=' + roledata.data[i].groupid + '>' + roledata.data[i].groupname + '</option>';
						}
				   		 $("#group option").remove();
				   		 $("#group").append(str);
						 form.render();
					} else {
							layer.msg("分组信息获取失败");
					}
				},
				error: function() {
					layer.msg("分组信息获取失败");
				}
			});
		 })
		
		
});
	
	</script>
</body>
</html>